//
//  CCTabbar.m
//  诚诚直播
//
//  Created by 廖易诚 on 16/7/9.
//  Copyright © 2016年 liaoyicheng. All rights reserved.
//

#import "CCTabbar.h"
#import "CameraViewController.h"

@interface CCTabbar ()

@property (weak, nonatomic) UIButton *home;

@property (weak, nonatomic) UIButton *centerBtn;

@property (weak, nonatomic) UIButton *mine;

@property (weak, nonatomic) UIButton *lastBtn;



@end

@implementation CCTabbar

- (instancetype)initWithFrame:(CGRect)frame {
    if ( self = [super initWithFrame:frame]) {
        UIButton *home = [[UIButton alloc] init];
        [self addSubview:home];
        self.home = home;
        [home setImage:[UIImage imageNamed:@"toolbar_home"] forState:UIControlStateNormal];
        [home setImage:[UIImage imageNamed:@"toolbar_home_sel"] forState:UIControlStateSelected];
        [home addTarget:self action:@selector(homeClick:) forControlEvents:UIControlEventTouchUpInside];
        home.selected = YES;
        self.lastBtn = home;
        home.tag = 1;
        
        UIButton *centerBtn = [[UIButton alloc] init];
        [self addSubview:centerBtn];
        self.centerBtn = centerBtn;
        [centerBtn setImage:[UIImage imageNamed:@"toolbar_live"] forState:UIControlStateNormal];
        [centerBtn addTarget:self action:@selector(clickCenterBtn) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *mine = [[UIButton alloc] init];
        [self addSubview:mine];
        self.mine = mine;
        [mine setImage:[UIImage imageNamed:@"toolbar_me"] forState:UIControlStateNormal];
        [mine setImage:[UIImage imageNamed:@"toolbar_me_sel"] forState:UIControlStateSelected];
        [mine addTarget:self action:@selector(homeClick:) forControlEvents:UIControlEventTouchUpInside];
        mine.tag = 2;
//        mine.selected = YES;
    }
    return self;
}

#pragma mark - 点击首页按钮
- (void)homeClick:(UIButton *)button {
    
    if (self.lastBtn == button) {
//        self.lastBtn.selected = NO;
        return;
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:@"selectViewController" object:@(button.tag)];
    
    self.lastBtn.selected = NO;
    button.selected = YES;
    self.lastBtn = button;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGFloat width = [UIScreen hm_screenWidth] / 3.0;
    CGFloat height = self.hm_height;
    
    
    self.home.frame = CGRectMake(0, 0, width, height);
    self.centerBtn.frame = CGRectMake(width, 0, width, height);
    self.mine.frame = CGRectMake(width * 2, 0, width, height);
}


#pragma mark - 中间按钮点击事件
-(void)clickCenterBtn{
    
    //NSLog(@"123");
    [[NSNotificationCenter defaultCenter]postNotificationName:@"beautifullove" object:nil];
    
    
    //[self presentViewController:cameraVC animated:YES completion:nil];
    
    


}

@end
